//
//  SearchCell.m
//  myhuibao
//
//  Created by li jun on 13-2-24.
//  Copyright (c) 2013年 myhuibao. All rights reserved.
//

#import "SearchCell.h"

@implementation SearchCell
@synthesize imageView;
@synthesize nameLable;
@synthesize addressLable;
@synthesize cuisineLable;
@synthesize scoreLable;
@synthesize distanceLable;
@synthesize discountLable;
@synthesize boxLabel;
@synthesize image;
@synthesize name;
@synthesize address;
@synthesize cuisine;
@synthesize score;
@synthesize distance;
@synthesize discount;
@synthesize imgRule;
@synthesize boxes;
@synthesize imgAgree;
@synthesize agree;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}
- (void)setImage:(UIImage *)img {
    if (![img isEqual:image]) {
        image = [img copy];
        self.imageView.image = image;
    }
}

-(void)setName:(NSString *)n {
    if (![n isEqualToString:name]) {
        name = [n copy];
        self.nameLable.text = name;
    }
}

-(void)setAddress:(NSString *)a{
    if ((NSNull*)a==[NSNull null]) {
        self.addressLable.text = @"";
    }else if (![a isEqualToString:address]) {
        address = [a copy];
        self.addressLable.text = address;
    }
}

-(void)setCuisine:(NSString *)c {
    if ((NSNull*)c != [NSNull null]  && ![c isEqualToString:cuisine]) {
        cuisine = [c copy];
        self.cuisineLable.text = cuisine;
    }
}

-(void)setScore:(NSNumber *)s {
//    if (![s isEqualToNumber:score]) {
        score = [s copy];
        int z = [score intValue];
    int empty=0;
    if(z==0){
        for(int i=0;i<5;i++){
            UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_star_empty.png"]];
            im.frame = CGRectMake(i*12+5, 0, 12, 12);
//            im.contentMode = UIViewContentModeScaleAspectFit;
            [self.scoreLable addSubview:im];
        }
    }else{
        for(int i=0;i<z;i++){
            UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_star.png"]];
            im.frame = CGRectMake(i*12+5, 0, 12, 12);
            [self.scoreLable addSubview:im];
            empty++;
        }
        if(z< [score floatValue]){
            UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_star_half.png"]];
            im.frame = CGRectMake((z)*12+5, 0, 12, 12);
            [self.scoreLable addSubview:im];
            empty++;
            z++;
        }
        for(int i=0;i<5-empty;i++){
            UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_star_empty.png"]];
            im.frame = CGRectMake(z++*12+5, 0, 12, 12);
            //            im.contentMode = UIViewContentModeScaleAspectFit;
            [self.scoreLable addSubview:im];
        }
    }
//        self.scoreLable.text = score;
//    }
}

-(void)setDistance:(NSString *)d{
    if (![d isEqualToString:distance]) {
        distance = [d copy];
        NSRange range=[distance rangeOfString:@"-"];
        if(range.location!=NSNotFound){
            self.distanceLable.text = distance;
        }else{
        float d  = [distance floatValue];
            if (d==0) {
                self.distanceLable.text=@"";
                imgRule.hidden = true;
                return;
            }
            if (d<1000) {
                self.distanceLable.text = [NSString stringWithFormat:@"%.0fm",d];
                imgRule.hidden=false;
            }else if(d>=1000 && d<=50000){
                self.distanceLable.text = [NSString stringWithFormat:@"%.1fkm",d/1000];
                imgRule.hidden=false;
            }else{
                self.distanceLable.text=@"";
                imgRule.hidden=true;
            }
        }
    }
}

-(void)setDiscount:(NSString *)d {
    if (![d isEqualToString:discount]) {
        discount = [d copy];
        self.discountLable.text = [discount isEqualToString:@"10"]==true?@"无":discount;
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void) setBoxes:(int)b
{
    if(b != 0)
        self.boxLabel.text = [NSString stringWithFormat:@"空包厢%d",b];
}
- (void) setAgree:(int)a
{
    self.imgAgree.hidden=true;
//    if(a == 0)
//        self.imgAgree.hidden=true;
//    else
//        self.imgAgree.hidden=false;
}
@end
